document.onkeydown = function(event) {
    var target, code, tag;
    if (!event) {
        event = window.event; //针对ie浏览器
        target = event.srcElement;
        code = event.keyCode;
        if (code == 13) {
            tag = target.tagName;
            if (tag == "TEXTAREA") { return true; }
            else { return false; }
        }
    }
    else {
        target = event.target; //针对遵循w3c标准的浏览器，如Firefox
        code = event.keyCode;
        if (code == 13) {
            tag = target.tagName;
            if (tag == "INPUT") { return false; }
            else { return true; }
        }
    }
};
    
//------- Start 判断输入的是否是证书和小数还有0
    
    function CupperCase(obj){//用户只能输入正负数与小数
            
        var inum = 5;

        var newValue;
        
        if(inum==1)
        {
            
            if(isNaN(obj.value) && !/^-$/.test(obj.value)){
                obj.value="";
            }
            if(!/^[+-]?\d*\.{0,1}\d{0,1}$/.test(obj.value)){
                obj.value=obj.value.replace(/\.\d{1,}$/,obj.value.substr(obj.value.indexOf('.'),inum));
                obj.value=newValue.replace('.','');
            }
        }
        else
        {
            
            if(isNaN(obj.value) && !/^-$/.test(obj.value)){
                obj.value="";
            }
            if(!/^[+-]?\d*\.{0,1}\d{0,1}$/.test(obj.value)){
                obj.value=obj.value.replace(/\.\d{1,}$/,obj.value.substr(obj.value.indexOf('.'),inum));
            }
        }
    }

    function CupperCase6(obj) {//用户只能输入正负数与小数

        var inum = 5;
        var newValue;

        if (inum == 1) {
            if (isNaN(obj.value) && !/^-$/.test(obj.value)) {
                obj.value = "";
            }
            if (!/^[+-]?\d*\.{0,1}\d{0,1}$/.test(obj.value)) {
                obj.value = obj.value.replace(/\.\d{1,}$/, obj.value.substr(obj.value.indexOf('.'), inum));
                obj.value = newValue.replace('.', ''); // 注意：这里使用了未定义的newValue
            }
        }
        else {
            if (isNaN(obj.value) && !/^-$/.test(obj.value)) {
                obj.value = "";
            }
            if (!/^[+-]?\d*\.{0,1}\d{0,1}$/.test(obj.value)) {
                obj.value = obj.value.replace(/\.\d{1,}$/, obj.value.substr(obj.value.indexOf('.'), inum));

            }
        }
        
    }
        
    function Wonkeyup(obj) {//用户只能输入正负数与小数

        var inum = 5;

                    
    // if(inum.length==5){inum==4;}else{inum=3;}
                    
        if(isNaN(obj.value) && !/^-$/.test(obj.value)){
            obj.value="";
        }
        if(!/^[+-]?\d*\.{0,1}\d{0,1}$/.test(obj.value)){
            obj.value=obj.value.replace(/\.\d{1,}$/,obj.value.substr(obj.value.indexOf('.'),inum));
        }
    }
    
    function Button2_onclick()
    {
        var mymessage = confirm("你确定需要保存吗？或者在检查一遍？");
            
        if(mymessage==true)
        {
            return true;        
                    
            
        }
        else
        {
            return false;
        }
                
    }
        
    function ResoultFloat(arg1,arg2){
        var t1=0,t2=0,r1,r2;
        try{t1=arg1.toString().split(".")[1].length}catch(e){}
        try{t2=arg2.toString().split(".")[1].length}catch(e){}
        with(Math){
            r1=Number(arg1.toString().replace(".",""));
            r2=Number(arg2.toString().replace(".",""));                
            return (r1/r2)*pow(10,t2-t1);
            }

    }

    function _SetDigitalInput(oInput, sensorIndex) {
        var isnum = 3; 

        // 确保变量在函数作用域内声明
        var i, j, k, f;

        if (oInput % 2 == 0) {
            i = oInput - 1;
            j = oInput + 1;
            k = oInput + 2;
            f = oInput - 2;
        } else {
            i = oInput + 1;
            j = oInput + 2;
            k = oInput + 3;
            f = oInput - 1;
        }   
        
        // 构建带索引的元素ID后缀
        const suffix = sensorIndex ? '_sensor' + sensorIndex : '';

        // 获取A232元素（也应该有传感器后缀）
        var fixElementId = "A232" + suffix;
        var fixElement = document.getElementById(fixElementId);
        var fix_value = parseFloat(fixElement.value) || 0;

        // 获取f_01元素
        var f01ElementId = "A" + oInput + suffix;
        var f01Element = document.getElementById(f01ElementId);
        var f_01 = parseFloat(f01Element.value) || 0;

        // 获取f_02元素
        var f02ElementId = "A" + i + suffix;
        var f02Element = document.getElementById(f02ElementId);
        var f_02 = f02Element ? (parseFloat(f02Element.value) || 0) : 0;
                    
        // 计算f_d
        var f_d = f_01 + f_02;

        // 计算f_x
        var f_x = ResoultFloat(f_d * 10000, 2) / 10000;

        // 设置A+j元素的值
        var ajElementId = "A" + j + suffix;
        var ajElement = document.getElementById(ajElementId);
        ajElement.value = changeTwoDecimal_y(f_x, 1); 


        // 计算误差
        var afElementId = "A" + f + suffix;
        var afElement = document.getElementById(afElementId);
        var ajValue = parseFloat(document.getElementById(ajElementId).value) || 0;
        var afValue = parseFloat(afElement.value) || 0;
        var f_d_error = (ajValue - afValue) / fix_value * 100;
        
        // 设置A+k元素的值
        var akElementId = "A" + k + suffix;
        var akElement = document.getElementById(akElementId);
        akElement.value = changeTwoDecimal_y(f_d_error, isnum); 

        //新增
        updateValue([4, 14, 24, 34, 44, 54, 64, 74, 84, 94, 104, 114, 124, 134, 144, 154, 164, 174, 184, 194, 204, 214, 224,
                    9, 19, 29, 39, 49, 59, 69, 79, 89, 99, 109, 119, 129, 139, 149, 159, 169, 179, 189, 199, 209, 219, 229], "A", suffix, "A_szwc");
    }

    function __SetDigitalInput(oInput, sensorIndex) {
        var isnum = 3;

        // 确保变量在函数作用域内声明
        var i, j, k, f;

        if (oInput % 2 == 0) {

            i = oInput + 1;
            j = oInput + 2;
            k = oInput + 3;
            f = oInput - 1;
        }
        else {

            i = oInput - 1;
            j = oInput + 1;
            k = oInput + 2;
            f = oInput - 2;
        }
        
        // 构建带索引的元素ID后缀
        const suffix = sensorIndex ? '_sensor' + sensorIndex : '';

        // 获取A232元素（也应该有传感器后缀）
        var fixElementId = "A232" + suffix;
        var fixElement = document.getElementById(fixElementId);
        if (!fixElement) {
            return;
        }
        var fix_value = parseFloat(fixElement.value) || 0;

        // 获取f_01元素
        var f01ElementId = "A" + oInput + suffix;
        var f01Element = document.getElementById(f01ElementId);
        if (!f01Element) {
            return;
        }
        var f_01 = parseFloat(f01Element.value) || 0;

        // 获取f_02元素
        var f02ElementId = "A" + i + suffix;
        var f02Element = document.getElementById(f02ElementId);
        var f_02 = f02Element ? (parseFloat(f02Element.value) || 0) : 0;

        // 计算f_d
        var f_d = f_01 + f_02;

        // 计算f_x
        var f_x = ResoultFloat(f_d * 10000, 2) / 10000;

        // 设置A+j元素的值
        var ajElementId = "A" + j + suffix;
        var ajElement = document.getElementById(ajElementId);
        if (ajElement) {
            ajElement.value = changeTwoDecimal_y(f_x, 1);
        } else {
            return;
        }

        // 计算误差
        var afElementId = "A" + f + suffix;
        var afElement = document.getElementById(afElementId);
        if (afElement) {
            // 注意：这里需要确保ajElement的值已经设置
            var ajValue = parseFloat(document.getElementById(ajElementId).value) || 0;
            var afValue = parseFloat(afElement.value) || 0;
            var f_d_error = (ajValue - afValue) / fix_value * 100;

            // 设置A+k元素的值
            var akElementId = "A" + k + suffix;
            var akElement = document.getElementById(akElementId);
            if (akElement) {
                akElement.value = changeTwoDecimal_y(f_d_error, isnum);
            } else {
                return;
            }
        } else {
            return;
        }

        //新增
        updateValue([4, 14, 24, 34, 44, 54, 64, 74, 84, 94, 104, 114, 124, 134, 144, 154, 164, 174, 184, 194, 204, 214, 224,
                    9, 19, 29, 39, 49, 59, 69, 79, 89, 99, 109, 119, 129, 139, 149, 159, 169, 179, 189, 199, 209, 219, 229], "A", suffix, "A_szwc");
    }

    function ___SetDigitalInput(oInput, sensorIndex) {
        // 构建带索引的元素ID后缀
        const suffix = sensorIndex ? '_sensor' + sensorIndex : '';
        
        var isnum = 1;
        if (oInput >= 0 && oInput <= 9) {
            var f_0 = parseFloat(document.getElementById("B0" + suffix).value == "" ? 0 : document.getElementById("B0" + suffix).value);
            var f_1 = parseFloat(document.getElementById("B1" + suffix).value == "" ? 0 : document.getElementById("B1" + suffix).value);
            var f_2 = parseFloat(document.getElementById("B2" + suffix).value == "" ? 0 : document.getElementById("B2" + suffix).value);
            var f_3 = parseFloat(document.getElementById("B3" + suffix).value == "" ? 0 : document.getElementById("B3" + suffix).value);
            var f_4 = parseFloat(document.getElementById("B4" + suffix).value == "" ? 0 : document.getElementById("B4" + suffix).value);
            var f_5 = parseFloat(document.getElementById("B5" + suffix).value == "" ? 0 : document.getElementById("B5" + suffix).value);
            var f_6 = parseFloat(document.getElementById("B6" + suffix).value == "" ? 0 : document.getElementById("B6" + suffix).value);
            var f_7 = parseFloat(document.getElementById("B7" + suffix).value == "" ? 0 : document.getElementById("B7" + suffix).value);
            var f_8 = parseFloat(document.getElementById("B8" + suffix).value == "" ? 0 : document.getElementById("B8" + suffix).value);
            var f_9 = parseFloat(document.getElementById("B9" + suffix).value == "" ? 0 : document.getElementById("B9" + suffix).value);

            var f_d = f_0 + f_1 + f_2 + f_3 + f_4 + f_5 + f_6 + f_7 + f_8 + f_9;

            var Avg_x = ResoultFloat(f_d * 10000, 10) / 10000;

            document.getElementById("B10" + suffix).value = changeTwoDecimal_y(Avg_x, isnum);

            var J_0 = (f_0 - Avg_x) * (f_0 - Avg_x);
            var J_1 = (f_1 - Avg_x) * (f_1 - Avg_x);
            var J_2 = (f_2 - Avg_x) * (f_2 - Avg_x);
            var J_3 = (f_3 - Avg_x) * (f_3 - Avg_x);
            var J_4 = (f_4 - Avg_x) * (f_4 - Avg_x);
            var J_5 = (f_5 - Avg_x) * (f_5 - Avg_x);
            var J_6 = (f_6 - Avg_x) * (f_6 - Avg_x);
            var J_7 = (f_7 - Avg_x) * (f_7 - Avg_x);
            var J_8 = (f_8 - Avg_x) * (f_8 - Avg_x);
            var J_9 = (f_9 - Avg_x) * (f_9 - Avg_x);

            var s_9 = (J_0 + J_1 + J_2 + J_3 + J_4 + J_5 + J_6 + J_7 + J_8 + J_9) / 9;

            var f_f = Math.pow(parseFloat(s_9), 0.5);

            document.getElementById("B11" + suffix).value = changeTwoDecimal_y(f_f / document.getElementById("B10" + suffix).value * 100, 3);

        }
        else {
            var f_12 = parseFloat(document.getElementById("B12" + suffix).value == "" ? 0 : document.getElementById("B12" + suffix).value);
            var f_13 = parseFloat(document.getElementById("B13" + suffix).value == "" ? 0 : document.getElementById("B13" + suffix).value);
            var f_14 = parseFloat(document.getElementById("B14" + suffix).value == "" ? 0 : document.getElementById("B14" + suffix).value);
            var f_15 = parseFloat(document.getElementById("B15" + suffix).value == "" ? 0 : document.getElementById("B15" + suffix).value);
            var f_16 = parseFloat(document.getElementById("B16" + suffix).value == "" ? 0 : document.getElementById("B16" + suffix).value);
            var f_17 = parseFloat(document.getElementById("B17" + suffix).value == "" ? 0 : document.getElementById("B17" + suffix).value);
            var f_18 = parseFloat(document.getElementById("B18" + suffix).value == "" ? 0 : document.getElementById("B18" + suffix).value);
            var f_19 = parseFloat(document.getElementById("B19" + suffix).value == "" ? 0 : document.getElementById("B19" + suffix).value);
            var f_20 = parseFloat(document.getElementById("B20" + suffix).value == "" ? 0 : document.getElementById("B20" + suffix).value);
            var f_21 = parseFloat(document.getElementById("B21" + suffix).value == "" ? 0 : document.getElementById("B21" + suffix).value);

            var f_22 = f_12 + f_13 + f_14 + f_15 + f_16 + f_17 + f_18 + f_19 + f_20 + f_21;

            var f_23 = ResoultFloat(f_22 * 10000, 10) / 10000;

            document.getElementById("B22" + suffix).value = changeTwoDecimal_y(f_23, isnum);

            var J_12 = (f_12 - f_23) * (f_12 - f_23);
            var J_13 = (f_13 - f_23) * (f_13 - f_23);
            var J_14 = (f_14 - f_23) * (f_14 - f_23);
            var J_15 = (f_15 - f_23) * (f_15 - f_23);
            var J_16 = (f_16 - f_23) * (f_16 - f_23);
            var J_17 = (f_17 - f_23) * (f_17 - f_23);
            var J_18 = (f_18 - f_23) * (f_18 - f_23);
            var J_19 = (f_19 - f_23) * (f_19 - f_23);
            var J_20 = (f_20 - f_23) * (f_20 - f_23);
            var J_21 = (f_21 - f_23) * (f_21 - f_23);

            var s_6 = (J_12 + J_13 + J_14 + J_15 + J_16 + J_17 + J_18 + J_19 + J_20 + J_21) / 9;

            var f_fx = Math.pow(parseFloat(s_6), 0.5);

            document.getElementById("B23" + suffix).value = changeTwoDecimal_y(f_fx / document.getElementById("B22" + suffix).value * 100, 3);
        }

        //新增
        updateValue([11, 23], "B", suffix, "B_szwc");
    }
        
    function SetDigitalInputC(oInput, sensorIndex) {
        // 构建带索引的元素ID后缀
        const suffix = sensorIndex ? '_sensor' + sensorIndex : '';
        
        var isnum = 1;

        if (oInput >= 0 && oInput <= 2) {
            var f_0 = parseFloat(document.getElementById("C0" + suffix).value == "" ? 0 : document.getElementById("C0" + suffix).value);
            var f_1 = parseFloat(document.getElementById("C1" + suffix).value == "" ? 0 : document.getElementById("C1" + suffix).value);
            var f_2 = parseFloat(document.getElementById("C2" + suffix).value == "" ? 0 : document.getElementById("C2" + suffix).value);

            var f_3 = f_0 + f_1 + f_2;

            var f_4 = ResoultFloat(f_3 * 10000, 3) / 10000;

            document.getElementById("C3" + suffix).value = changeTwoDecimal_y(f_4, isnum); 
        }
        else if (oInput >= 5 && oInput <= 7) {
            var f_5 = parseFloat(document.getElementById("C5" + suffix).value == "" ? 0 : document.getElementById("C5" + suffix).value);
            var f_6 = parseFloat(document.getElementById("C6" + suffix).value == "" ? 0 : document.getElementById("C6" + suffix).value);
            var f_7 = parseFloat(document.getElementById("C7" + suffix).value == "" ? 0 : document.getElementById("C7" + suffix).value);

            var f_8 = f_5 + f_6 + f_7;

            var f_9 = ResoultFloat(f_8 * 10000, 3) / 10000;

            document.getElementById("C8" + suffix).value = changeTwoDecimal_y(f_9, isnum);
        }
        else if (oInput >= 10 && oInput <= 12) {
            var f_10 = parseFloat(document.getElementById("C10" + suffix).value == "" ? 0 : document.getElementById("C10" + suffix).value);
            var f_11 = parseFloat(document.getElementById("C11" + suffix).value == "" ? 0 : document.getElementById("C11" + suffix).value);
            var f_12 = parseFloat(document.getElementById("C12" + suffix).value == "" ? 0 : document.getElementById("C12" + suffix).value);

            var f_13 = f_10 + f_11 + f_12;

            var f_14 = ResoultFloat(f_13 * 10000, 3) / 10000;

            document.getElementById("C13" + suffix).value = changeTwoDecimal_y(f_14, isnum);
        }
        else {
            var f_15 = parseFloat(document.getElementById("C15" + suffix).value == "" ? 0 : document.getElementById("C15" + suffix).value);
            var f_16 = parseFloat(document.getElementById("C16" + suffix).value == "" ? 0 : document.getElementById("C16" + suffix).value);
            var f_17 = parseFloat(document.getElementById("C17" + suffix).value == "" ? 0 : document.getElementById("C17" + suffix).value);

            var f_18 = f_15 + f_16 + f_17;

            var f_19 = ResoultFloat(f_18 * 10000, 3) / 10000;

            document.getElementById("C18" + suffix).value = changeTwoDecimal_y(f_19, isnum);             
        }

        V_01 = parseFloat(document.getElementById("C3" + suffix).value == "" ? 0 : document.getElementById("C3" + suffix).value);
        V_02 = parseFloat(document.getElementById("C8" + suffix).value == "" ? 0 : document.getElementById("C8" + suffix).value);

        V_03 = (V_01 - V_02) == 0 ? changeTwoDecimal_y((V_01 / 0.05) / 1000, isnum) * 1000000000000 : changeTwoDecimal_y((V_01 / (V_01 - V_02)) / 1000, isnum) * 1000000000000;

        if (V_03 < 0) {
            V_03 = -V_03;
        } else {
            V_03 = V_03;
        }

        document.getElementById("C4" + suffix).value = document.getElementById("C9" + suffix).value = V_03.toExponential(1);

        V_04 = parseFloat(document.getElementById("C13" + suffix).value == "" ? 0 : document.getElementById("C13" + suffix).value);
        V_05 = parseFloat(document.getElementById("C18" + suffix).value == "" ? 0 : document.getElementById("C18" + suffix).value);

        V_06 = (V_04 - V_05) == 0 ? (changeTwoDecimal_y((V_04 / 0.05) / 1000, isnum) * 1000000000000) : changeTwoDecimal_y((V_04 / (V_04 - V_05)) / 1000, isnum) * 1000000000000;

        if (V_06 < 0) {
            V_06 = -V_06;
        } else {
            V_06 = V_06;
        }

        document.getElementById("C14" + suffix).value = document.getElementById("C19" + suffix).value = V_06.toExponential(1);

        // 新增代码：比较C4和C14，将较小值赋给C_srzk + suffix
        var c4Value = parseFloat(document.getElementById("C4" + suffix).value) || 0;
        var c14Value = parseFloat(document.getElementById("C14" + suffix).value) || 0;
        var minValue = Math.min(Math.abs(c4Value), Math.abs(c14Value));
        
        var c_srzkElement = document.getElementById("C_srzk" + suffix);
        if (c_srzkElement) {
            c_srzkElement.value = minValue.toExponential(1);
        }
    }

    function SetDigitalInputD(oInput, sensorIndex) {
        // 构建带索引的元素ID后缀
        const suffix = sensorIndex ? '_sensor' + sensorIndex : '';
        
        var isnum = 1;

        if (oInput >= 0 && oInput <= 2) {
            var f_0 = parseFloat(document.getElementById("D0" + suffix).value == "" ? 0 : document.getElementById("D0" + suffix).value);
            var f_1 = parseFloat(document.getElementById("D1" + suffix).value == "" ? 0 : document.getElementById("D1" + suffix).value);
            var f_2 = parseFloat(document.getElementById("D2" + suffix).value == "" ? 0 : document.getElementById("D2" + suffix).value);

            var f_3 = f_0 + f_1 + f_2;

            var f_4 = ResoultFloat(f_3 * 10000, 3) / 10000;

            document.getElementById("D3" + suffix).value = changeTwoDecimal_y(f_4, isnum); 
        }
        else {
            var f_5 = parseFloat(document.getElementById("D5" + suffix).value == "" ? 0 : document.getElementById("D5" + suffix).value);
            var f_6 = parseFloat(document.getElementById("D6" + suffix).value == "" ? 0 : document.getElementById("D6" + suffix).value);
            var f_7 = parseFloat(document.getElementById("D7" + suffix).value == "" ? 0 : document.getElementById("D7" + suffix).value);

            var f_8 = f_5 + f_6 + f_7;

            var f_9 = ResoultFloat(f_8 * 10000, 3) / 10000;

            document.getElementById("D8" + suffix).value = changeTwoDecimal_y(f_9, isnum);
        }

        V_02 = parseFloat(document.getElementById("D8" + suffix).value == "" ? 0 : document.getElementById("D8" + suffix).value);
        V_01 = parseFloat(document.getElementById("D3" + suffix).value == "" ? 0 : document.getElementById("D3" + suffix).value);

        document.getElementById("D4" + suffix).value = document.getElementById("D9" + suffix).value = Math.abs((V_02 - V_01) * 0.000000000001).toExponential(1);
    }

    function SetDigitalInputF(oInput, sensorIndex) {
        // 构建带索引的元素ID后缀
        const suffix = sensorIndex ? '_sensor' + sensorIndex : '';
        
        var f_1 = parseFloat(document.getElementById("F1" + suffix).value == "" ? 0 : document.getElementById("F1" + suffix).value);
        var f_2 = parseFloat(document.getElementById("F2" + suffix).value == "" ? 0 : document.getElementById("F2" + suffix).value);
        var f_3 = parseFloat(document.getElementById("F3" + suffix).value == "" ? 0 : document.getElementById("F3" + suffix).value);
        var f_4 = parseFloat(document.getElementById("F4" + suffix).value == "" ? 0 : document.getElementById("F4" + suffix).value);
        var f_5 = parseFloat(document.getElementById("F5" + suffix).value == "" ? 0 : document.getElementById("F5" + suffix).value);
        var f_6 = parseFloat(document.getElementById("F6" + suffix).value == "" ? 0 : document.getElementById("F6" + suffix).value);
            
        var f_d = f_1 + f_2 + f_3 + f_4 + f_5 + f_6;

        var Avg_x = changeTwoDecimal_y(ResoultFloat(f_d*1000, 6)/1000,4);

        document.getElementById("F7" + suffix).value = Avg_x;

        document.getElementById("F8" + suffix).value = changeTwoDecimal_y((Avg_x - parseFloat(document.getElementById("F11" + suffix).value)) / parseFloat(document.getElementById("F11" + suffix).value) * 100, 2);

        var J_1 = (f_1 - Avg_x) * (f_1 - Avg_x);
        var J_2 = (f_2 - Avg_x) * (f_2 - Avg_x);
        var J_3 = (f_3 - Avg_x) * (f_3 - Avg_x);
        var J_4 = (f_4 - Avg_x) * (f_4 - Avg_x);
        var J_5 = (f_5 - Avg_x) * (f_5 - Avg_x);
        var J_6 = (f_6 - Avg_x) * (f_6 - Avg_x);

        var s_7 = (J_1 + J_2 + J_3 + J_4 + J_5 + J_6) / 5;

        var f_f = Math.pow(parseFloat(s_7), 0.5);

        document.getElementById("F9" + suffix).value = changeTwoDecimal_y((f_f / Avg_x) * 100, 1);
    }

    //滴定管相关函数
    function searchChange(ddgIndex) {
        // 如果没有直接传递索引，则尝试从触发事件的元素中获取索引
        let actualIndex = ddgIndex;
        let suffix = '';
        
        // 如果没有传递索引参数，尝试从事件源获取
        if (typeof ddgIndex === 'undefined' || ddgIndex === null) {
            // 尝试从触发事件的元素获取索引
            if (event && event.target) {
                const targetId = event.target.id;
                const match = targetId.match(/E3_ddg(\d+)/);
                if (match) {
                    actualIndex = match[1];
                }
            }
        }
        
        // 构建带索引的元素ID后缀
        if (actualIndex) {
            suffix = '_ddg' + actualIndex;
        }
        
        console.log("查找元素 E3" + suffix);
        
        // 获取E3元素并添加错误检查
        var e3Element = document.getElementById("E3" + suffix);
        if (!e3Element) {
            console.error("找不到元素 E3" + suffix);
            // 如果带索引的元素找不到，尝试查找不带索引的元素
            e3Element = document.getElementById("E3");
        }
        
        var resultValue = e3Element;
        var pindex = resultValue.selectedIndex;
        
        var e4Element = document.getElementById("E4" + suffix);
        
        e4Element.value = resultValue.options[pindex].value;
    }

    // 修改searchChangeE0函数以支持多滴定管索引
    function searchChangeE0(oInput, ddgIndex) {
        // 构建带索引的元素ID后缀
        const suffix = ddgIndex ? '_ddg' + ddgIndex : '';
        
        for (var j = 15; j <= 64; j++) {
            var element = document.getElementById("E" + j + suffix);
            if (element) {
                element.style.visibility = "visible";
                element.value = "";
            }
        }
        
        // 为所有带索引的元素设置初始值
        const elementsToReset = ["15", "20", "25", "30", "35", "40", "45", "50", "55", "60"];
        elementsToReset.forEach(id => {
            var element = document.getElementById("E" + id + suffix);
            if (element) {
                element.value = "0.0000";
            }
        });

        var resultValue = document.getElementById("E0" + suffix);
        if (!resultValue) {
            console.error("找不到元素 E0" + suffix);
            return;
        }
        
        var pindex = resultValue.selectedIndex;
        var resulttxt = resultValue.options[pindex].text;

        if (resulttxt == 5) {
            document.getElementById("E5" + suffix).value = 2.5;
            document.getElementById("E6" + suffix).value = 2.5;
            document.getElementById("E7" + suffix).value = 5;
            document.getElementById("E8" + suffix).value = 5;

            for (var i = 35; i <= 64; i++) {
                var element = document.getElementById("E" + i + suffix);
                if (element) {
                    element.style.visibility = "hidden";
                }
            }

            for (var k = 9; k <= 14; k++) {
                var element = document.getElementById("E" + k + suffix);
                if (element) {
                    element.value = "/";
                }
            }
            
            // document.getElementById("E65" + suffix).value = "A:±0.010; B:±0.020";
            document.getElementById("E_A" + suffix).value = "±0.010";
            document.getElementById("E_B" + suffix).value = "±0.020";
        }
        
        if (resulttxt == 10) {
            document.getElementById("E5" + suffix).value = 5;
            document.getElementById("E6" + suffix).value = 5;
            document.getElementById("E7" + suffix).value = 10;
            document.getElementById("E8" + suffix).value = 10;

            for (var i = 35; i <= 64; i++) {
                var element = document.getElementById("E" + i + suffix);
                if (element) {
                    element.style.visibility = "hidden";
                }
            }

            for (var k = 9; k <= 14; k++) {
                var element = document.getElementById("E" + k + suffix);
                if (element) {
                    element.value = "/";
                }
            }
            
            // document.getElementById("E65" + suffix).value = "A:±0.025;B: ±0.050";
            document.getElementById("E_A" + suffix).value = "±0.025";
            document.getElementById("E_B" + suffix).value = "±0.050";
        }  

        if (resulttxt == 20) {
            document.getElementById("E5" + suffix).value = 5;
            document.getElementById("E6" + suffix).value = 5;
            document.getElementById("E7" + suffix).value = 10;
            document.getElementById("E8" + suffix).value = 10;
            document.getElementById("E9" + suffix).value = 15;
            document.getElementById("E10" + suffix).value = 15;
            document.getElementById("E11" + suffix).value = 20;
            document.getElementById("E12" + suffix).value = 20;

            for (var i = 55; i <= 64; i++) {
                var element = document.getElementById("E" + i + suffix);
                if (element) {
                    element.style.visibility = "hidden";
                }
            } 

            document.getElementById("E13" + suffix).value = "/";
            document.getElementById("E14" + suffix).value = "/";
            // document.getElementById("E65" + suffix).value = "A:±0.035;B: ±0.070";
            document.getElementById("E_A" + suffix).value = "±0.035";
            document.getElementById("E_B" + suffix).value = "±0.070";
            
        }
        
        if (resulttxt == 25) {
            document.getElementById("E5" + suffix).value = 5;
            document.getElementById("E6" + suffix).value = 5;
            document.getElementById("E7" + suffix).value = 10;
            document.getElementById("E8" + suffix).value = 10;
            document.getElementById("E9" + suffix).value = 15;
            document.getElementById("E10" + suffix).value = 15;
            document.getElementById("E11" + suffix).value = 20;
            document.getElementById("E12" + suffix).value = 20;
            document.getElementById("E13" + suffix).value = 25;
            document.getElementById("E14" + suffix).value = 25; 

            // document.getElementById("E65" + suffix).value = "A:±0.04;B: ±0.08";
            document.getElementById("E_A" + suffix).value = "±0.04";
            document.getElementById("E_B" + suffix).value = "±0.08";
        }
        
        if (resulttxt == 50) {
            document.getElementById("E5" + suffix).value = 10;
            document.getElementById("E6" + suffix).value = 10;
            document.getElementById("E7" + suffix).value = 20;
            document.getElementById("E8" + suffix).value = 20;
            document.getElementById("E9" + suffix).value = 30;
            document.getElementById("E10" + suffix).value = 30;
            document.getElementById("E11" + suffix).value = 40;
            document.getElementById("E12" + suffix).value = 40;
            document.getElementById("E13" + suffix).value = 50;
            document.getElementById("E14" + suffix).value = 50; 
            
            // document.getElementById("E65" + suffix).value = "A:±0.05;B: ±0.10";
            document.getElementById("E_A" + suffix).value = "±0.05";
            document.getElementById("E_B" + suffix).value = "±0.10";
        }

        if (resulttxt == 100) {
            document.getElementById("E5" + suffix).value = 20;
            document.getElementById("E6" + suffix).value = 20;
            document.getElementById("E7" + suffix).value = 40;
            document.getElementById("E8" + suffix).value = 40;
            document.getElementById("E9" + suffix).value = 60;
            document.getElementById("E10" + suffix).value = 60;
            document.getElementById("E11" + suffix).value = 80;
            document.getElementById("E12" + suffix).value = 80;
            document.getElementById("E13" + suffix).value = 100;
            document.getElementById("E14" + suffix).value = 100; 
            
            // document.getElementById("E65" + suffix).value = "A:±0.10;B: ±0.20";
            document.getElementById("E_A" + suffix).value = "±0.10";
            document.getElementById("E_B" + suffix).value = "±0.20";
        }
    }

    // 修改SetDigitalInputE函数以支持多滴定管索引
    function SetDigitalInputE(oInput, ddgIndex) {
        // 构建带索引的元素ID后缀
        const suffix = ddgIndex ? '_ddg' + ddgIndex : '';
        
        var isnum = 4;

        if (oInput % 5 == 0) {
            i = oInput + 1;
            j = oInput + 2;
            k = oInput + 3;
            n = oInput + 4;

            document.getElementById("E" + j + suffix).value = changeTwoDecimal_y(
                document.getElementById("E" + i + suffix).value - document.getElementById("E" + oInput + suffix).value, 
                isnum
            );                
            document.getElementById("E" + k + suffix).value = changeTwoDecimal_y(
                parseFloat(document.getElementById("E" + i + suffix).value - document.getElementById("E" + oInput + suffix).value) * 
                parseFloat(document.getElementById("E4" + suffix).value), 
                isnum
            );
        } else {
            i = oInput - 1;
            j = oInput + 1;
            k = oInput + 2;
            n = oInput + 3;

            document.getElementById("E" + j + suffix).value = changeTwoDecimal_y(
                document.getElementById("E" + oInput + suffix).value - document.getElementById("E" + i + suffix).value, 
                isnum
            );
            document.getElementById("E" + k + suffix).value = changeTwoDecimal_y(
                parseFloat(document.getElementById("E" + oInput + suffix).value - document.getElementById("E" + i + suffix).value) * 
                parseFloat(document.getElementById("E4" + suffix).value), 
                isnum
            );
        }

        if (oInput == 15 || oInput == 16) {
            f = 5;
        } else if (oInput == 20 || oInput == 21) {
            f = 6;
        } else if (oInput == 25 || oInput == 26) {
            f = 7;
        } else if (oInput == 30 || oInput == 31) {
            f = 8;
        } else if (oInput == 35 || oInput == 36) {
            f = 9;
        } else if (oInput == 40 || oInput == 41) {
            f = 10;
        } else if (oInput == 45 || oInput == 46) {
            f = 11;
        } else if (oInput == 50 || oInput == 51) {
            f = 12;
        } else if (oInput == 55 || oInput == 56) {
            f = 13;
        } else if (oInput == 60 || oInput == 61) {
            f = 14;
        }

        document.getElementById("E" + n + suffix).value = changeTwoDecimal_y(
            document.getElementById("E" + f + suffix).value - document.getElementById("E" + k + suffix).value, 
            isnum
        );

        // 新增代码：计算平均值
        // E_pjz1 = (E19 + E24) / 2
        var e19 = parseFloat(document.getElementById("E19" + suffix).value) || 0;
        var e24 = parseFloat(document.getElementById("E24" + suffix).value) || 0;
        var pjz1 = (e19 + e24) / 2;
        document.getElementById("E_pjz1" + suffix).value = changeTwoDecimal_y(pjz1, isnum);
        
        // E_pjz2 = (E29 + E34) / 2
        var e29 = parseFloat(document.getElementById("E29" + suffix).value) || 0;
        var e34 = parseFloat(document.getElementById("E34" + suffix).value) || 0;
        var pjz2 = (e29 + e34) / 2;
        document.getElementById("E_pjz2" + suffix).value = changeTwoDecimal_y(pjz2, isnum);
        
        // E_pjz3 = (E39 + E44) / 2
        var e39 = parseFloat(document.getElementById("E39" + suffix).value) || 0;
        var e44 = parseFloat(document.getElementById("E44" + suffix).value) || 0;
        var pjz3 = (e39 + e44) / 2;
        document.getElementById("E_pjz3" + suffix).value = changeTwoDecimal_y(pjz3, isnum);
        
        // E_pjz4 = (E49 + E54) / 2
        var e49 = parseFloat(document.getElementById("E49" + suffix).value) || 0;
        var e54 = parseFloat(document.getElementById("E54" + suffix).value) || 0;
        var pjz4 = (e49 + e54) / 2;
        document.getElementById("E_pjz4" + suffix).value = changeTwoDecimal_y(pjz4, isnum);
        
        // E_pjz5 = (E59 + E64) / 2
        var e59 = parseFloat(document.getElementById("E59" + suffix).value) || 0;
        var e64 = parseFloat(document.getElementById("E64" + suffix).value) || 0;
        var pjz5 = (e59 + e64) / 2;
        document.getElementById("E_pjz5" + suffix).value = changeTwoDecimal_y(pjz5, isnum);

        //新增
        updateValue([1, 2, 3, 4, 5], "E_pjz", suffix, "E_result");

    }

    function changeTwoDecimal_f(x)
    {
        var f_x = parseFloat(x);
        if (isNaN(f_x))
        {
            alert('function:changeTwoDecimal->parameter error');
            return false;
        }
        f_x = Math.round(f_x*10000)/10000;
        var s_x = f_x.toString();
        var pos_decimal = s_x.indexOf('.');
        if (pos_decimal < 0)
        {
            pos_decimal = s_x.length;
            s_x += '.';
        }
        while (s_x.length <= pos_decimal + 3)
        {
            s_x += '0';
        }
        return s_x;
    }

    function changeTwoDecimal_y(s_x, inum) {

        var s_x_old = s_x;

        
            

        if (String(s_x).length >= 10) {

            s_x = s_x.toFixed(inum + 1);

        }
        

        if (isNaN(s_x)) {
            alert('function:changeTwoDecimal->parameter error');
            return false;
        }

        // 转成字符型

        s_x = s_x.toString();


        //确定是否有小数点

        var pdecimal = s_x.indexOf('.');


        if (pdecimal < 0) {
            pdecimal = s_x.length;
            s_x += '.';
        }

        while (s_x.length < parseInt(parseInt(pdecimal) + parseInt(inum + 2))) {
            s_x += '0';
        }



        var inums = inum + s_x.indexOf('.');



        var iReturnValue = "";


        if (s_x.length > (parseInt(inums) + 2)) {
            s_x = s_x.substring(0, (parseInt(inums) + 2));
        }


        var s_x_l = parseInt(s_x.substring(s_x.length - 1, s_x.length));

        var s_x_2 = parseInt(s_x.substring(s_x.length - 2, s_x.length - 1));



        var kj = parseFloat(Math.pow(10, -inum).toFixed(inum));

        

        if (s_x_l == 5) {


            if (Math.abs(parseFloat(s_x_old)) > Math.abs(parseFloat(s_x))) {


                iReturnValue = parseFloat(s_x) > 0 ? String((Math.round(parseFloat(s_x.substring(0, parseInt(inums + 1))) * 1000000) + Math.round(parseFloat(kj) * 1000000)) / 1000000) : String((Math.round(parseFloat(s_x.substring(0, parseInt(inums + 1))) * 1000000) - Math.round(parseFloat(kj) * 1000000)) / 1000000);

                
            } else {

                if (s_x_2 == 0 || s_x_2 % 2 == 0) {

                    iReturnValue = (s_x.substring(0, parseInt(inums + 1)));


                }
                else if (s_x_2 != 0 && s_x_2 % 2 != 0) {

                    iReturnValue = parseFloat(s_x) > 0 ? String((Math.round(parseFloat(s_x.substring(0, parseInt(inums + 1))) * 1000000) + Math.round(parseFloat(kj) * 1000000)) / 1000000) : String((Math.round(parseFloat(s_x.substring(0, parseInt(inums + 1))) * 1000000) - Math.round(parseFloat(kj) * 1000000)) / 1000000);

                }
            }
        }
        else {


            if (s_x_l >= 6) {


                iReturnValue = parseFloat(s_x) > 0 ? String((Math.round(parseFloat(s_x.substring(0, parseInt(inums + 1))) * 1000000) + Math.round(parseFloat(kj) * 1000000)) / 1000000) : String((Math.round(parseFloat(s_x.substring(0, parseInt(inums + 1))) * 1000000) - Math.round(parseFloat(kj) * 1000000)) / 1000000);


            }
            else {

                iReturnValue = (s_x.substring(0, parseInt(inums + 1)));


            }

        }

        if (inum > 0) {

            var ih = iReturnValue.indexOf('.');


            if (ih < 0) {
                ih = iReturnValue.length;
                iReturnValue += '.';
            }

            while (iReturnValue.length < parseInt(parseInt(ih) + parseInt(inum + 1))) {
                iReturnValue += '0';
            }



            var ihs = inum + s_x.indexOf('.'); 


            if (iReturnValue.length > (parseInt(ihs) + 1)) {
                iReturnValue = iReturnValue.substring(0, (parseInt(ihs) + 1));
            }
        } 
        return iReturnValue;
    }
        

        
    function Setnum(oInput)
    {
        var f_x = parseFloat(document.getElementById("A1PH_Dy10").value);
            
        document.getElementById("C49").value=f_x;
        document.getElementById("C98").value=-f_x;
        document.getElementById("C106").value=f_x;              
            
    }


    function FChanged(oInput) {

        if (oInput == 2) {

            document.getElementById("F0").value = document.getElementById("BLPH_FW_02").value;

        }
        else {
            document.getElementById("F11").value = document.getElementById("BLPH_FW_03").value;

        }


    }

    // 新增函数：计算绝对值最大的正值
    function updateValue(fieldIndexes, fieldPrefix, suffix, targetFieldId) {
        var values = [];
        
        // 收集所有非空字段的值
        for (var idx = 0; idx < fieldIndexes.length; idx++) {
            var fieldId = fieldPrefix + fieldIndexes[idx] + suffix;
            var fieldElement = document.getElementById(fieldId);
            
            if (fieldElement && fieldElement.value !== "" && fieldElement.value !== "/") {
                values.push(parseFloat(fieldElement.value));
            }
        }
        
        // 如果有值，计算绝对值最大的值
        if (values.length > 0) {
            var maxAbsValue = values[0];
            var maxAbs = Math.abs(values[0]);
            
            for (var i = 1; i < values.length; i++) {
                var absValue = Math.abs(values[i]);
                // 如果找到更大的绝对值，或者绝对值相等但当前是正值，则更新
                if (absValue > maxAbs || (absValue === maxAbs && values[i] > 0 && maxAbsValue < 0)) {
                    maxAbsValue = values[i];
                    maxAbs = absValue;
                }
            }
            
            // 设置目标字段的值
            var targetElement = document.getElementById(targetFieldId + suffix);
            if (targetElement) {
                var inumElement = document.getElementById("A1PH_Level08" + suffix);
                // 如果A1PH_Level08元素不存在或无法获取其值，则使用默认值
                var decimalPlaces = (inumElement && inumElement.value && inumElement.value.length == 5) ? 3 : 2;
                targetElement.value = changeTwoDecimal_y(maxAbsValue, decimalPlaces);
            }
        }
    }